package com.bit.java;

public class Test9 {
    public static int midCheak(int[] array, int val) {
        int left = 0;
        int right = array.length - 1;
        while(left <= right) {
            int mid = (right + left) / 2;
            if(array[mid] > val) {
                right--;
            } else if(array[mid] < val) {
                left++;
            } else {
                return mid;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9,};
        int ret = midCheak(array,8);
        System.out.println(ret);
    }
}
